<?php if (!defined('THINK_PATH')) exit(); /*a:4:{s:73:"D:\php\fastadmin\public/../application/admin\view\fruit\config\index.html";i:1572083760;s:59:"D:\php\fastadmin\application\admin\view\layout\default.html";i:1570347774;s:56:"D:\php\fastadmin\application\admin\view\common\meta.html";i:1570347774;s:58:"D:\php\fastadmin\application\admin\view\common\script.html";i:1570347774;}*/ ?>
<!DOCTYPE html>
<html lang="<?php echo $config['language']; ?>">
    <head>
        <meta charset="utf-8">
<title><?php echo (isset($title) && ($title !== '')?$title:''); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="renderer" content="webkit">

<link rel="shortcut icon" href="/assets/img/favicon.ico" />
<!-- Loading Bootstrap -->
<link href="/assets/css/backend<?php echo \think\Config::get('app_debug')?'':'.min'; ?>.css?v=<?php echo \think\Config::get('site.version'); ?>" rel="stylesheet">

<!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
<!--[if lt IE 9]>
  <script src="/assets/js/html5shiv.js"></script>
  <script src="/assets/js/respond.min.js"></script>
<![endif]-->
<script type="text/javascript">
    var require = {
        config:  <?php echo json_encode($config); ?>
    };
</script>
    </head>

    <body class="inside-header inside-aside <?php echo defined('IS_DIALOG') && IS_DIALOG ? 'is-dialog' : ''; ?>">
        <div id="main" role="main">
            <div class="tab-content tab-addtabs">
                <div id="content">
                    <div class="row">
                        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                            <section class="content-header hide">
                                <h1>
                                    <?php echo __('Dashboard'); ?>
                                    <small><?php echo __('Control panel'); ?></small>
                                </h1>
                            </section>
                            <?php if(!IS_DIALOG && !$config['fastadmin']['multiplenav']): ?>
                            <!-- RIBBON -->
                            <div id="ribbon">
                                <ol class="breadcrumb pull-left">
                                    <li><a href="dashboard" class="addtabsit"><i class="fa fa-dashboard"></i> <?php echo __('Dashboard'); ?></a></li>
                                </ol>
                                <ol class="breadcrumb pull-right">
                                    <?php foreach($breadcrumb as $vo): ?>
                                    <li><a href="javascript:;" data-url="<?php echo $vo['url']; ?>"><?php echo $vo['title']; ?></a></li>
                                    <?php endforeach; ?>
                                </ol>
                            </div>
                            <!-- END RIBBON -->
                            <?php endif; ?>
                            <div class="content">
                                <style>
    .td_value{
        text-align: center; vertical-align: middle;
    }
    .td_value input{
        text-align: center;
    }
</style>
<div class="panel panel-default panel-intro">
    <?php echo build_heading(); ?>
    <div class="panel-body" id="app">
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade active in" id="one">
                <div class="widget-body no-padding">
                    <div class="toolbar" style="margin-bottom: 10px">表名：<?php echo $db_name; ?></div>

                    <table  class="table table-striped table-bordered table-hover table-nowrap" data-operate-edit="1" data-operate-del="1" width="100%">
                        <thead>
                        <tr>
                            <th style="text-align: center; vertical-align: middle; " data-field="id">
                                <div class="th-inner ">主键自增</div>
                                <div class="fht-cell"></div>
                            </th>
                            <th style="text-align: center; vertical-align: middle; " data-field="name">
                                <div class="th-inner ">彩灯名称</div>
                                <div class="fht-cell"></div>
                            </th>
                            <th style="text-align: center; vertical-align: middle; " data-field="odds">
                                <div class="th-inner ">赔率</div>
                                <div class="fht-cell"></div>
                            </th>
                            <th style="text-align: center; vertical-align: middle; " data-field="probability">
                                <div class="th-inner ">正常水果命中概率({{probability_total}})---<a class="btn btn-danger" v-on:click="update_probability()" style="padding: 2px 9px;"><i class="fa fa-upload"></i>更新</a></div>
                                <div class="fht-cell"></div>
                            </th>
                            <th style="text-align: center; vertical-align: middle; " data-field="lucky_probability">
                                <div class="th-inner ">命中lucky之后水果命中概率({{lucky_probability_total}})---<a class="btn btn-danger" v-on:click="update_lucky_probability()" style="padding: 2px 9px;"><i class="fa fa-upload"></i>更新</a></div>
                                <div class="fht-cell"></div>
                            </th>
                            <th style="text-align: center; vertical-align: middle; " data-field="jackpot">
                                <div class="th-inner ">特殊结果从奖池抽取额外奖励的百分比</div>
                                <div class="fht-cell"></div>
                            </th>
                        </tr>
                        </thead>

                        <tbody data-listidx="0">
                            <tr data-index="0" v-for="(value,key) in allconfig">
                                <td class="td_value">{{value.id}}</td>
                                <td class="td_value">{{value.name}}</td>
                                <td class="td_value">{{value.odds}}</td>
                                <td class="td_value"><input type="text" :value="value.probability"  v-bind:disabled="value.probability > 0 ? false:true" :name="'probability'+value.id" :id="'probability'+value.id" @input="jisuan1()"></td>
                                <td class="td_value"><input type="text" :value="value.lucky_probability" v-bind:disabled="value.lucky_probability > 0 ? false:true" :name="'lucky_probability'+value.id" :id="'lucky_probability'+value.id" @input="jisuan2()"></td>
                                <td class="td_value">{{value.jackpot}}</td>
                            </tr>
                        </tbody>

                    </table>

                </div>
            </div>

        </div>
    </div>
</div>
<script type="text/javascript" src="/assets/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/assets/vue/vue.js"></script>
<script type="text/javascript" src="/assets/vue/vue-resource.js"></script>
<script type="text/javascript">
    jQuery(function() {
        var app = new Vue({
            el: '#app',
            data: {
                allconfig:{},
                probability_total:0,
                lucky_probability_total:0
            },
            beforeCreate: function() {

            },
            created: function() {

            },
            beforeMount: function() {

            },
            beforeUpdate: function() {

            },
            beforeDestroy: function() {

            },
            destroyed: function() {

            },
            mounted: function() {
                this.$nextTick(function() {
                    this.kaishi();
                });

            },
            methods: {
                kaishi: function() {

                    this.getallconfig();

                },
                getallconfig:function(){
                    var that  = this;
                    this.$http.get("config/allconfig").then(function(data){
                        var shuju = data.body;
                        this.allconfig = shuju;
                        $.each(shuju,function (index,element) {
                            console.log();
                            if(element['probability'] !=-1){
                                that.probability_total = accAdd(that.probability_total ,element['probability'])
                            }
                            if(element['lucky_probability'] !=-1){
                                that.lucky_probability_total = accAdd(that.lucky_probability_total ,element['lucky_probability'])
                            }

                        })
                    });


                },
                jisuan1:function(){
                    var temp = 0;
                    for (var i = 1; i <= 14; i++) {
                        var protemp = document.getElementById("probability" + i).value;
                        if( protemp != -1){
                            temp = accAdd(temp,protemp);
                        }
                    }

                    this.probability_total = temp;

                },
                jisuan2:function(){
                    var temp = 0;
                    for (var i = 1; i <= 14; i++) {
                        var protemp = document.getElementById("lucky_probability" + i).value;
                        if( protemp != -1){
                            temp = accAdd(temp,protemp);
                        }
                    }

                    //this.lucky_probability_total = temp;

                },

                update_probability:function () {
                    var probability_all = 0;
                    var probability =[];
                    var data = [];


                    for (var i = 1; i <= 14; i++) {
                        var temp = {};
                        var probability_zhi = document.getElementById("probability" + i).value;
                        temp.id = i;
                        temp.probability = probability_zhi;
                        if( probability_zhi != -1){
                            probability_all = accAdd(probability_all,probability_zhi);
                        }
                        data.push(temp);
                    }

                    if(probability_all != 1){

                        alert(probability_all + "水果命中概率总和不为1,请合理计算");
                        return;
                    }


                    //提交方法 ...code....
                    this.$http.post(
                        "config/up_probability",
                        {data:data}, { emulateJSON: true }

                    ).then(
                        function(response) {
                            var fanhui = response.body;

                            alert(fanhui.msg);
                            location.reload();




                        }
                    );


                },
                update_lucky_probability:function () {
                    var lucky_probability_all = 0;
                    var lucky_probability =[];
                    for (var i = 1; i <= 14; i++) {

                        var lucky_probability_zhi = document.getElementById("lucky_probability" + i).value;
                        if( lucky_probability_zhi != -1) {
                            lucky_probability_all = accAdd(lucky_probability_all,lucky_probability_zhi);;
                        }
                        lucky_probability.push(lucky_probability_zhi);

                    }

                    if(lucky_probability_all != 1){

                        alert(lucky_probability_all + "水果命中概率总和不为1,请合理计算");
                        return;
                    }

                    //提交方法 ...code....


                },




            }

        })

    });
    function accAdd(arg1, arg2) {
        var r1, r2, m, c;
        try {
            r1 = arg1.toString().split(".")[1].length;
        }
        catch (e) {
            r1 = 0;
        }
        try {
            r2 = arg2.toString().split(".")[1].length;
        }
        catch (e) {
            r2 = 0;
        }
        c = Math.abs(r1 - r2);
        m = Math.pow(10, Math.max(r1, r2));
        if (c > 0) {
            var cm = Math.pow(10, c);
            if (r1 > r2) {
                arg1 = Number(arg1.toString().replace(".", ""));
                arg2 = Number(arg2.toString().replace(".", "")) * cm;
            } else {
                arg1 = Number(arg1.toString().replace(".", "")) * cm;
                arg2 = Number(arg2.toString().replace(".", ""));
            }
        } else {
            arg1 = Number(arg1.toString().replace(".", ""));
            arg2 = Number(arg2.toString().replace(".", ""));
        }
        return (arg1 + arg2) / m;
    }
</script>


                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script src="/assets/js/require<?php echo \think\Config::get('app_debug')?'':'.min'; ?>.js" data-main="/assets/js/require-backend<?php echo \think\Config::get('app_debug')?'':'.min'; ?>.js?v=<?php echo htmlentities($site['version']); ?>"></script>
    </body>
</html>